package educationaladministrationsystem.CSM.Mapper.Service.StudentAndTeacher.Teacher;

import educationaladministrationsystem.CSM.Mapper.Service.ServiceInterface.StudentAndTeacherInterface.Teacher.TeacherSupplementalGrades;
import educationaladministrationsystem.Class.Course;
import educationaladministrationsystem.Class.Student;
import educationaladministrationsystem.CSM.Mapper.StudentAndTeacher.Teacher.TeacherSupplementalGradesMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.DecimalFormat;
import java.util.List;

@Service
public class TeacherSupplementalGradesService implements TeacherSupplementalGrades {
    @Autowired
    private TeacherSupplementalGradesMapper teacherSupplementalGradesMapper;

    @Override
    public List<Course> getAllCourse(String id) {
        return teacherSupplementalGradesMapper.getAllCourse(id);
    }

    @Override
    public int getHaveSupplePeople(String id) {
        Integer result = teacherSupplementalGradesMapper.getHaveSupplePeople(id);
        return result == null ? 0 : result;
    }

    @Override
    public List<Student> getAllStudentInformationByClassId(String id, int page, int pageNumber) {
        return teacherSupplementalGradesMapper.getAllStudentInformationByClassId(id, (page - 1) * pageNumber, pageNumber);
    }

    @Override
    public void uploadCredit(String classId, String studentId, double credit, double classCredit) {
        DecimalFormat decimalFormat = new DecimalFormat("#.##");
        teacherSupplementalGradesMapper.uploadCredit(classId, studentId, credit, Double.parseDouble(decimalFormat.format(credit * classCredit)));
    }

    @Override
    public int getPageSum(String id, int pageNumber) {
        return (int) Math.ceil((double) teacherSupplementalGradesMapper.getCountFromStudentWithCourse(id) / pageNumber);
    }

    @Override
    public int getAllCourseCount(String id) {
        return teacherSupplementalGradesMapper.getAllCourseCount(id);
    }

    @Override
    public int haveSuppleCourseCount(String id) {
        return teacherSupplementalGradesMapper.haveSuppleCourseCount(id);
    }
}
